package com.tian.print.app;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.cdf.CDFPTKAndroidImpl;
import com.tian.print.R;
import com.tian.print.bean.UserInfo;

public class RepositoryManagerApp extends Application {

    private static RepositoryManagerApp app;
    private static UserInfo userInfo;
    public static CDFPTKAndroid cdf = null;
    public static int ConnectOrClose = 0;

    static class PrintHandler extends Handler {

        public PrintHandler() {
        }

        @Override
        public void handleMessage(Message msg) {

            Log.d("connect_p", msg.toString());

            if (msg.what == CDFPTKAndroid.PTK_MSG_WHAT_WIFICONNECT) {
                if (msg.arg1 == 0) {
                    ConnectOrClose = 1;
                    Toast.makeText(getAppContext(), R.string.connect_success, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getAppContext(), R.string.disconnect_wifi, Toast.LENGTH_SHORT).show();
                }
                getAppContext().sendBroadcast(new Intent(AppConfig.PRINT_CONNECT));
            }
        }
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        app = this;

    }

    @Override
    public void onCreate() {
        super.onCreate();
        cdf = new CDFPTKAndroidImpl(this, new PrintHandler());
    }


    public static RepositoryManagerApp getAppContext() {
        return app;
    }

    public static RepositoryManagerApp getApp() {
        return app;
    }

    public static void setApp(RepositoryManagerApp app) {
        RepositoryManagerApp.app = app;
    }

    public static UserInfo getUserInfo() {
        return userInfo;
    }

    public static void setUserInfo(UserInfo userInfo) {
        RepositoryManagerApp.userInfo = userInfo;
    }

}
